<!--
* description: 门店销售扩展信息-修改弹窗
* author: dinggf
* createdDate: 2019-10-19
-->
<template>
  <section class="editDlrSales">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="1000px"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />
      <div
        v-if="tableComponents.length > 0"
        ref="conTitleHeight"
        class="filter-container filter-title"
      >编辑区</div>
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            :disabled="comp.disabled"
            :org-id="formField.dlrId"
            :car-brand-code="formField.carBrandCode"
            :is-require="comp.isRequire"
            :parent-fileds="comp.parentFileds || ''"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
        <div slot="footer" class="dialog-footer">
          <el-button
            v-for="comp in tableButtons"
            :key="comp.compKey"
            :type="comp.type"
            :icon="comp.icon"
            @click="comp.clickEvent"
          >{{ comp.text }}</el-button>
        </div>
      </div>
      <div
        v-if="tableComponents.length > 0"
        ref="conTitleHeight"
        class="filter-container filter-title"
      >联系人列表</div>
      <maintain
        :key="maintainPopupsKey"
        :dynamic-edit-row-data="maintainRowData"
        :popups-visible="maintainPopupsVisible"
        :showdlr-id1="showdlrId1"
      />
    </el-dialog>
  </section>
</template>

<script>
// import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { formMixins } from '@/components/mixins/formMixins'
import { orgApis } from '@/api/apiList/org'
import OneTableTemplate from '@/components/templates/popupsOneTable'
export default {
  components: {
    OneTableTemplate,
    Maintain: () => import('./maintain'), dialogHeader: () => import('@/components/dialogHeader') // 弹窗标题
  },
  mixins: [formMixins],
  props: {
    showdlrId: {
      type: String,
      default: function() {
        return ''
      }
    },
    orgId: {
      type: String,
      default: function() {
        return ''
      }
    }
  },
  data() {
    var popupsPageCode = 'orgDlrSalesEdit'
    return {
      orgId1: this.orgId,
      popupsPageCode: 'orgDlrSalesEdit',
      showdlrId1: '',
      maintainPopupsVisible: true, // 是否显示历史价格弹窗
      // editPopupsVisible: false, //是否显示历史价格弹窗
      maintainPopupsKey: 'maintain1', // 新增、编辑弹窗Key
      maintainPopupsState: '', // 新增、编辑弹窗状态（add/edit/view）
      maintainRowData: {}, // 新增、编辑行对象
      // 门店销售扩展信息保存
      apiConfig: orgApis.mdmOrgDlrMutationSaleSave,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          icon: 'iconfont  icon-preservation',
          clickEvent: () => this.save(),
          text: this.$t('sys.button.save')
        }, // 保存
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          icon: 'iconfont  icon-reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset')
        }, // 重置
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          icon: 'iconfont  icon-cancel',
          clickEvent: () => this.sendCode(),
          text: this.$t('sys.button.cancel')
        } // 取消
      ],

      // 动态组件-查询条件（上部分表单）
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[popupsPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[popupsPageCode].formComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[popupsPageCode]
            .formComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '门店：',
              codeField: 'dlrId',
              textField: 'dlrShortName',
              isRequire: true,
              component: () => import('@/components/org/orgDlr'),
              type: 'propus',
              isMust: true,
              disabled: true
            },
            // {
            //   compKey: "compKey2",
            //   labelName: "ANSWER编码",
            //   codeField: "dlrAnswerCode",
            //   isRequire: true,
            //   component: () => import("@/components/org/commonInput"),
            //   type: "inputText",
            //   isMust: true
            // },
            {
              compKey: 'compKey3',
              labelName: '门店规模：',
              codeField: 'driveType',
              lookuptype: 'DB0402',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isMust: true
            },
            // {
            //   compKey: "compKey4",
            //   labelName: "SAP编码",
            //   codeField: "sapDlrId",
            //   component: () => import("@/components/org/commonInput"),
            //   type: "inputText",
            //   disabled: true,
            //   isMust: true
            // },
            {
              compKey: 'compKey5',
              labelName: '传真(售前)：',
              codeField: 'saleFax',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            // {
            //   compKey: "compKey6",
            //   labelName: "排放标准",
            //   codeField: "emissionStandard",
            //   lookuptype: "DB0079",
            //   component: () => import("@/components/org/LookupValue"),
            //   type: "dropdownList",
            //   isMust: true
            // },
            {
              compKey: 'compKey7',
              labelName: '适应气候：',
              codeField: 'climateStatus',
              lookuptype: 'VE0180',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              isMust: true
            },
            {
              compKey: 'compKey8',
              labelName: '销售热线：',
              codeField: 'saleTel',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey9',
              labelName: '销售联络EMAIL：',
              codeField: 'saleEmail',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey10',
              labelName: '门店地址：',
              codeField: 'linkAddr',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey11',
              labelName: '邮编：',
              codeField: 'zip',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey12',
              labelName: '整车收货地址：',
              codeField: 'linkManAddr',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey13',
              labelName: '销售品牌：',
              // span:24,
              codeField: 'carBrandCode', // 中台没有该字段
              parentFileds: 'dlrId-carBrandCode',
              component: () =>
                import('@/components/org/saleCarBrand/saleCarBrand'),
              type: 'dropdownList',
              isMust: true,
              isMul: true
            }, // 东风日产-日产
            {
              compKey: 'compKey14',
              labelName: 'ANSWER编码：',
              // span:24,
              isRequire: true,
              codeField: 'dlrAnswerCode', // 中台没有该字段
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              validrule: { maxlength: 4 },
              isMust: true,
              isMul: true
            }, // dlrAnswer
            {
              compKey: 'compKey15',
              labelName: 'SAP编码：',
              // span:24,
              codeField: 'sapDlrId', // 中台没有该字段
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              isMul: true
            } // dlrAnswer
          ],
      textMap: {
        edit: '编辑'
      },
      // 上部分表单
      formField: {
        dlrId: '',
        driveType: '',
        dlrShortName: '',
        saleFax: '',
        climateStatus: '',
        saleTel: '',
        saleEmail: '',
        linkAddr: '',
        zip: '',
        linkManAddr: '',
        dlrAnswerCode: '',
        sapDlrId: '',
        emissionStandard: '',
        carBrandCode: '',
        orgId: ''
      }
    }
  },
  created() {
    this.showdlrId1 = this.showdlrId
  },
  methods: {

    save() {
      this.$utils.validataMoth(this, 'validpopup')
      if (this.valid) {
        const queryObj = {
          // 保存mutation
          type: 'mutation',
          // 保存API配置对象
          apiConfig: orgApis.mdmOrgDlrMutationSaleSave,
          // 条件/实体参数（变量），根据typeParam中的定义配置
          variables: {
            // 当前中台使用的名称有dataInfo、info，具体查看API文档
            dataInfo: {
              dlrId: this.formField.dlrId,
              driveType: this.formField.driveType,
              saleFax: this.formField.saleFax,
              climateStatus: this.formField.climateStatus,
              saleTel: this.formField.saleTel,
              saleEmail: this.formField.saleEmail,
              linkAddr: this.formField.linkAddr,
              zip: this.formField.zip,
              linkManAddr: this.formField.linkManAddr,
              carBrandCode: this.formField.carBrandCode,
              sapDlrId: this.formField.sapDlrId,
              dlrAnswerCode: this.formField.dlrAnswerCode
            }
          }
        }
        // 转换了中台请求格式数据
        var paramD = this.$getParams(queryObj)
        // 调用中台API方法（可复用）
        this.$requestAPI(paramD).then(response => {
          if (response.result === '1') {
            // 保存成功
            this.$message({
              message: '保存成功',
              type: 'success',
              uration: 2000
            })
            this.sendCode('1')
          } else {
            // 保存失败
            // this.sendCode('0')
            this.$message({
              message:
                '保存失败：' +
                response.msg,
              type: 'warn',
              uration: 2000
            })
          }
        })
      }
    }
  }
}
</script>

<style lang='scss' scoped>
// /deep/ .filter-params .el-col label.el-checkbox {
//   width: 20%;
//   font-size: 12px;
// }
// /deep/ .filter-params .el-col-24 label {
//   width: 93px;
//   margin-right: 1.5%;
// }
// /deep/ .filter-params .el-col label {
//   max-width: 50%;
// }
// /deep/ .filter-params .el-col-4 label {
//   width: 50%;
// }
// /deep/ .el-dialog__body .maintainHandle .el-table {
//   height: 150px !important;
// }
</style>
